
<?
//引入所有子系统信息
include_once("../../../common/script/extender_import.php");


//**获取当前板块资料，必然载入，后续很多读取板块数据库的表格，都写成动态的了。
include_once("script/this_plate.php");



//获取板块的设置
include_once("../model/setting.php");




//根据页面数量信息，筛选信息，创造url，供页码,跳转等使用
include_once("script/set_url.php");




    //拆成数组，用于循环比较
    $tag_array = explode(";", $setting['basic']['tag']);


    //把用户的标签拆成数组，用于比较
    $now_member_tag_array=explode(",",$data['member']['tag']);
    //把用户的评级拆成数组，用于比较
    $now_member_rank_array=explode(",",$data['member']['rank']);



//获取分类树
//按结构输出分类树
$category=select_lines_all_items($table_prefix.$this_plate['table']['category'],$sort,
                                 "parent_nid = 'root' and (delete_status != '已删除' or delete_status is null)","");


//循环，查找数据库中，parent_nid = 当前的 nid的值
foreach($category as $key=>$value)
{
    $category[$key]['level2']=select_lines_all_items($table_prefix.$this_plate['table']['category'],$sort,
                                                     "parent_nid = '{$value['nid']}' and (delete_status != '已删除' or delete_status is null) ","");

    // 确保 level2_data 是数组
    if (is_array($category[$key]['level2']))
    {
        //开始循环第三级
        foreach($category[$key]['level2'] as $k=>$v)
        {
            $category[$key]['level2'][$k]['level3']=select_lines_all_items($table_prefix.$this_plate['table']['category'],
                                                                           $sort,"parent_nid = '{$v['nid']}' and (delete_status != '已删除' or delete_status is null) ","");
        }
    }

}



//循环数组，组成select要用的json格式
foreach($category as $key=>$value)
{
    $_category[$key]['id']      = $value['nid'];
    $_category[$key]['title']   = $value['name'];

    $value['level2'] = isset($value['level2']) ? $value['level2'] : [];

    if(count($value['level2'])>0)
    {
        foreach ($value['level2'] as $key2=>$value2)
        {
            $_category[$key]['children'][$key2]['title'] = $value2['name'];
            $_category[$key]['children'][$key2]['id'] = $value2['nid'];

            $value2['level3'] = isset($value2['level3']) ? $value2['level3'] : [];

            if(count($value2['level3'])>0)
            {
                foreach ($value2['level3'] as $key3=>$value3)
                {
                    $_category[$key]['children'][$key2]['children'][$key3]['title'] = $value3['name'];
                    $_category[$key]['children'][$key2]['children'][$key3]['id'] = $value3['nid'];
                }
            }
        }

    }
}


$category_select_list = json_encode($_category, JSON_UNESCAPED_UNICODE);









?>

